    <!DOCTYPE html>
    <html>

    <head>
        <title>客户</title>
            <#include "../../include/head-file.ftl">

    </head>

    <body>
    <div id="form" v-cloak>
        <el-header class="ms-header ms-tr" height="50px">
            <el-button type="primary" class="iconfont icon-baocun" size="default" @click="save()" :loading="saveDisabled">保存</el-button>
            <el-button size="default" class="iconfont icon-fanhui" plain @click="back()">返回</el-button>
        </el-header>
        <el-main class="ms-container" v-loading="loading">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="right" size="default">

            <!--玄乐账号-->

	        <el-form-item  label="玄乐账号" prop="xl">
	            <el-input
                        v-model="form.xl"
                         :disabled="false"
                          :readonly="false"
                          :style="{width:  '100%'}"
                          :clearable="true"
                        placeholder="请输入玄乐账号">
                </el-input>
	        </el-form-item>   
        <!--金钱-->
    
        <el-form-item  label="金钱" prop="moneyLz">
            <el-input
                v-model="form.moneyLz"
                :style="{width: '100%'}"
placeholder="请输入金钱"      
               :formatter="(value) => {
  					        return (`¥`+value).replace(/\B(?=(\d{3})+(?!\d))/g, ',').replace(/[^\d.¥,]|(?<=\..*)\./g, '').replace(/^(0+)/g, '');
                }"
              :parser="(value) => value.replace(/\¥\s?|(,*)/g, '')"
              />
        </el-form-item>
   
        <!--区长-->
    
        <el-form-item  label="区长" prop="selectCodes">
                    <el-select   v-model="form.selectCodes"
                               :style="{width: '50%'}"
                               :filterable="false"
                               :disabled="false"
                               :multiple="false" :clearable="true"
                            placeholder="请选择区长">
                        <el-option v-for='item in selectCodesOptions' :key="item.value" :value="item.value"
                                   :label="item.label"></el-option>
                    </el-select>
        </el-form-item>
   
            </el-form>
        </el-main>
    </div>
    </body>

    </html>

<script>
    var formVue = new _Vue({
        el: '#form',

        data:function() {
            return {
                loading:false,
                saveDisabled: false,
                // 区长
                selectCodesOptions:[{"value":"code","label":"区长"},{"value":"city","label":"市长"},{"value":"","label":""}],
                //表单数据
                form: {
                    // 玄乐账号
                    xl:'',
                    // 金钱
                    moneyLz:0,
                    				// 区长
                    				selectCodes:"",

                },
                rules:{
                        // 玄乐账号
                        xl: [{"min":0,"max":255,"message":"单行文本长度必须为0-255"}],

                },

            }
        },
        watch:{

        },
        components:{
         },
        computed:{
        },
        methods: {

            back: function (){
                ms.util.openSystemUrl("/game/user/index.do",true);
            },

            save:function() {
                var that = this;
                var url = ms.manager + "/game/user/save.do"
                if (that.form.id > 0) {
                    url = ms.manager + "/game/user/update.do";
                }

                this.$refs.form.validate(function(valid) {
                    if (valid) {
                        that.saveDisabled = true;
                        var form = JSON.parse(JSON.stringify(that.form));
                        ms.http.post(url, form).then(function (res) {
                            if (res.result) {
                                that.$notify({
                                    title: "成功",
                                    message: "保存成功",
                                    type: 'success'
                                });
                                ms.util.openSystemUrl("/game/user/index.do",that.form.id > 0);
                            } else {
                                that.$notify({
                                    title: "错误",
                                    message: res.msg,
                                    type: 'warning'
                                });
                            }

                            that.saveDisabled = false;
                        }).catch(function (err) {
                            console.log(err);
                            that.saveDisabled = false;
                        });
                    } else {
                        return false;
                    }
                })
            },

            //获取当前客户
            get:function(id) {
                var that = this;
                this.loading = true
                ms.http.get(ms.manager + "/game/user/get.do", {"id":id}).then(function (res) {
                    that.loading = false
                    if(res.result&&res.data) {
                   
                        that.form = res.data;
                    }
                });
            },
                   //区长  列表格式化
		selectCodesFormat:function(row, column, cellValue, index){
			var value="";
                        
			if(cellValue){
				var data = this.selectCodesOptions.find(function(value){
					return value.value==cellValue;
				})
				if(data&&data.label){
					value = data.label;
				}
			}

			return value;
		},

		//获取selectCodes数据源


        },
        created:function() {
            var that = this;
           

            this.form.id = ms.util.getParameter("id");
            if (this.form.id) {
                this.get(this.form.id);
            }
        }
    });

</script>
    <style scoped>
    </style>
